## read camera intrinsics

import json,os
import numpy as np
import open3d as o3d
import sys
import tqdm 
sys.path.append(os.getcwd())
from mask.create_mask import get_camera_intrinsic


# to scene_camera_json
#"0": {"cam_K": [572.4114, 0.0, 325.2611, 0.0, 573.57043, 242.04899, 0.0, 0.0, 1.0], "depth_scale": 1.0},

def main():

    folder = 'E:/pose/datasets/obj_ac/obj_000003/train_pbr/000001/'
    length = len(os.listdir(f"{folder}/pose"))
    camera_intrinsics, K = get_camera_intrinsic(folder)
    K = K.flatten().tolist()
    scene_camera = {
        i: {"cam_K": K, "depth_scale": 1.0} for i in tqdm.tqdm(range(length))
    }
    # Save scene_camera as a JSON file
    with open(f'{folder}/scene_camera.json', 'w') as f:
        json.dump(scene_camera, f)

if __name__ == "__main__":
    main()

